package com.onur.mdia;

import java.io.IOException;

import com.onur.mdia.R.id;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;



public class Record extends Activity {
    
     //Called when the activity is first created. 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.record);
    
       
        final String mFileName = null;
       
      
        	       Button veri=(Button) findViewById(R.id.buton);
        	       veri.setOnClickListener(new View.OnClickListener() {
        	    	
					public void onClick(View v) {
						// TODO Auto-generated method stub
						MediaRecorder recorder =  new MediaRecorder();
					  
					    
					  
					    try {
					    	recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
						    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
						    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
						    recorder.setOutputFile(mFileName);
							recorder.prepare();
							recorder.start();
							mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
							mFileName += "/audiorecordtest.3gp";
						} catch (IllegalStateException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					        
						
					}
				});
        	       
        	       
        	       
        	       
        	       Button dur=(Button) findViewById(R.id.buton1);
        	       dur.setOnClickListener(new View.OnClickListener() {
					
					public void onClick(View v) {
						// TODO Auto-generated method stub
						MediaRecorder recorder =  new MediaRecorder();
					  
					    
					  
					    try {
					    	recorder.stop();
					    	MediaPlayer mPlayer = new MediaPlayer();
					    	 mPlayer.setDataSource(mFileName);
	        	               mPlayer.prepare();
	        	               mPlayer.start();
						} catch (IllegalStateException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}
					        
						
					}
				});
        	       
        	       
        	     
        	       
        	       
    
}}